package ru.rchervot.sanasar.client.view;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DisclosurePanel;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Widget;

public abstract class AbstractFilterView extends Composite implements AbstractFilterPresenter.Display {
	
	private HorizontalPanel pButton = new HorizontalPanel();
	private DisclosurePanel disclosurePanel;
	private final Button closeButton = new Button("x");
	private final String filterName;
	private final String filterNameHuman;
	
	private Presenter presenter;
	
	public AbstractFilterView(String filterName, String filterNameHuman) {
		this.filterName = filterName;
		this.filterNameHuman = filterNameHuman;
		
		disclosurePanel = new DisclosurePanel(filterNameHuman);
		disclosurePanel.setWidth("650px");
		disclosurePanel.setAnimationEnabled(true);
		disclosurePanel.setOpen(true);
		
		
		pButton.setStylePrimaryName("AbstractFilterView_pButton");
		pButton.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		pButton.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		pButton.setWidth("100%");
		
		pButton.add(closeButton);
		
		HorizontalPanel basePanel = new HorizontalPanel();
		basePanel.setWidth("100%");
		basePanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
		basePanel.setStylePrimaryName("AbstractFilterView");
		
		basePanel.add(disclosurePanel);
		basePanel.setCellWidth(disclosurePanel, "650px");
		basePanel.add(pButton);
		
		this.initWidget(basePanel);
	}
	
	public Button getRemoveFilterButton() {
		return closeButton;
	}

	protected void setContent(Widget content) {
		disclosurePanel.setContent(content);
	}
	
	@Override
	public void show() {
		super.setVisible(true);
		pButton.setHeight(disclosurePanel.getHeader().getOffsetHeight() + "px");
	}

	@Override
	public void hide() {
		super.setVisible(false);
		pButton.setHeight(disclosurePanel.getHeader().getOffsetHeight() + "px");
	}
	
	@Override
	public String getFilterName() {
		return filterName;
	}
	
	@Override
	public String getFilterNameHuman() {
		return filterNameHuman;
	}
	
	@Override
	public void setPresenter(Presenter presenter) {
		this.presenter = presenter;
	}
	
}
